<?php

/*
    Copyright (C) 2025  Derek Kaser

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

namespace Tailscale;

use EDACerton\PluginUtils\Translator;

if ( ! defined(__NAMESPACE__ . '\PLUGIN_ROOT') || ! defined(__NAMESPACE__ . '\PLUGIN_NAME')) {
    throw new \RuntimeException("Common file not loaded.");
}

$tr = $tr ?? new Translator(PLUGIN_ROOT);

$tailscaleConfig = $tailscaleConfig ?? new Config();

if ( ! $tailscaleConfig->Enable) {
    echo($tr->tr("tailscale_disabled"));
    return;
}

if ( ! defined(__NAMESPACE__ . "\PLUGIN_ROOT")) {
    throw new \RuntimeException("PLUGIN_ROOT not defined");
}

$signingNode = false;

$tailscaleInfo = $tailscaleInfo ?? new Info($tr);

switch (true) {
    case $tailscaleInfo->getTailscaleLockSigning():
        require PLUGIN_ROOT . "/include/tailscale-lock/signing.php";
        break;
    case $tailscaleInfo->getTailscaleLockSigned():
        require PLUGIN_ROOT . "/include/tailscale-lock/signed.php";
        break;
    case $tailscaleInfo->getTailscaleLockEnabled():
        require PLUGIN_ROOT . "/include/tailscale-lock/locked.php";
        break;
    default:
        require PLUGIN_ROOT . "/include/tailscale-lock/disabled.php";
        break;
}
